﻿using System;
using System.Collections.Generic;

namespace EnterpriseFramework.DataAccess
{
    public sealed class Command
    {
        public Command() { }

        private string text;
        private System.Data.CommandType _commandType = System.Data.CommandType.Text;

        private List<IParameter> parameters = new List<IParameter>();

        public System.Data.CommandType commandType
        {
            get { return _commandType; }
            set { _commandType = value; }
        }

        /// <summary>
        /// Gets or sets the SQL statement of this command.
        /// </summary>
        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        /// <summary>
        /// Gets the number of parameters.
        /// </summary>
        public int Count
        {
            get { return parameters.Count; }
        }

        /// <summary>
        /// Adds a parameter created from a column with given name.
        /// </summary>
        /// <param name="p">parameter created from a column with given name</param>
        public void Add(IParameter p)
        {
            parameters.Add(p);
        }

        public void Add(List<IParameter> paramList)
        {
            parameters.AddRange(paramList);
        }

        public void Add(IParameter[] paramList)
        {
            parameters.AddRange(paramList);
        }

        /// <summary>
        /// Returns a parameter at the given index.
        /// </summary>
        /// <param name="index">parameter index</param>
        /// <returns>parameter at the given index</returns>
        public IParameter Get(int index)
        {
            if (index >= 0 && index < parameters.Count)
                return parameters[index];
            return null;
        }

        public List<IParameter> Parameters
        {
            get { return parameters; }
        }

        /// <summary>
        /// Returns a copy of this command.
        /// </summary>
        /// <returns>copy of this command</returns>
        //public _Command Clone()
        //{
        //    _Command clone = new _Command();
        //    clone.Text = this.text;
        //    foreach (Parameter p in parameters)
        //        clone.Add(p.Clone());
        //    return clone;
        //}
    }
}
